Page({
  data: {
    time: '12:30',
    userInfo: {
      name: '张晓燕',
      role: '店长',
      store: '墨莉婚纱总店',
      avatar: '/assets/images/default-avatar.png'
    },
    lastPasswordChange: '2024-02-15',
    notifications: {
      newClient: true,
      schedule: true,
      order: true
    },
    accountsCount: 15,
    backupFrequency: '每日'
  },

  onLoad: function() {
    this.updateTime();
    this.getTimerID = setInterval(this.updateTime, 60000);
    
    // 加载用户信息
    this.loadUserInfo();
  },
  
  onUnload: function() {
    clearInterval(this.getTimerID);
  },
  
  updateTime: function() {
    const date = new Date();
    const hours = date.getHours();
    const minutes = date.getMinutes();
    this.setData({
      time: `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`
    });
  },
  
  loadUserInfo: function() {
    // 这里可以从全局存储或服务器加载用户信息
    // 示例代码：
    const app = getApp();
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo
      });
    }
  },
  
  navigateToProfile: function() {
    wx.navigateTo({
      url: '/pages/profile/profile'
    });
  },
  
  changePassword: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  accountSecurity: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  toggleNotification: function(e) {
    const type = e.currentTarget.dataset.type;
    const checked = e.detail.value;
    const key = `notifications.${type}`;
    
    const data = {};
    data[key] = checked;
    
    this.setData(data);
    
    // 保存设置到服务器
    // 示例代码：
    /*
    wx.request({
      url: 'https://api.example.com/settings/notifications',
      method: 'POST',
      data: {
        type: type,
        enabled: checked
      },
      success: (res) => {
        console.log('通知设置已保存', res);
      },
      fail: (err) => {
        console.error('保存设置失败', err);
      }
    });
    */
  },
  
  roleManagement: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  staffAccounts: function() {
    wx.navigateTo({
      url: '/pages/staff/staff'
    });
  },
  
  operationLogs: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  storeInfo: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  dataBackup: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  customization: function() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  
  signOut: function() {
    wx.showModal({
      title: '提示',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          // 清除登录状态
          // getApp().globalData.userInfo = null;
          
          // 跳转到登录页面
          wx.reLaunch({
            url: '/pages/login/login'
          });
        }
      }
    });
  }
}); 